import React, { Component } from 'react';
import './manage.css'
import System from './System';
import { adminCheck, adminUnlog } from '../Redux/ActionCreator';
import { connect } from 'react-redux';
import {withRouter} from "react-router-dom";
import { Loginout_tim } from '../IM/actiontim';

//头部蓝色栏，只包含头部
class SIdmenu extends Component {
    constructor(props) {
        super(props)
        console.log(props)
        this.props.dispatch(adminCheck())
    }
    render(props) {
        return (
            // 头部
            <div className="box_head">
                    <span className='head_left'>百果园后台管理系统</span>
                    {this.props.adminreducer.map((item) => {
                        if (item.admin_name == JSON.parse(localStorage.getItem('admin')).admin_name) {
                            return <button className='head_right'>{item.admin_name}</button>
                        }
                    })}
                    {/* 退出 */}
                    <button className='exit'
                        onClick={() => {
                            // console.log(this.props)
                            this.props.history.push('/');
                            localStorage.removeItem('admin')
                            this.props.dispatch(adminUnlog())
                            Loginout_tim()
                        }}
                    >退出</button>
                </div>
        );
    }
}
const mapStateToProps = (state) => ({
    adminreducer: state.adminreducer,
    loginReducer: state.loginReducer
})
export default connect(mapStateToProps)(withRouter(SIdmenu));